package offer;

/**
 * @Author Elephas
 * @Date 2022/1/14
 **/
public class ReverseLeftWords {
    public String reverseLeftWords(String s,int n){
        char[] chars = s.toCharArray();
        reverse(chars,0,n-1);
        reverse(chars,n,s.length()-1);
        reverse(chars,0,s.length()-1);
        return String.copyValueOf(chars);
    }

    public void reverse(char[] chars,int left,int right){
        while(left <= right){
            char temp = chars[left];
            chars[left] = chars[right];
            chars[right] = temp;
            left++;
            right--;
        }
    }
}
